package com.yc.chatroom.server.util;

import com.yc.chatroom.common.Constant;
import com.yc.chatroom.common.dto.ResultDto;
import io.netty.channel.ChannelHandlerContext;

public class ChannelUtil {

    /**
     * 结束连接
     * 发消息，等3秒，然后断开连接
     * @param channel
     * @param msg
     * @throws InterruptedException
     */
    public static void overChannel(ChannelHandlerContext channel, String msg) throws InterruptedException {
        sendMsg(channel, msg);
        Thread.sleep(3000);
        channel.close();
    }

    public static void sendMsg(ChannelHandlerContext channel, String msg) {
        ResultDto res = new ResultDto();
        res.setCode(Constant.RESULT_CODE_SYSTEM_NOTIFY);
        res.setMsg(msg);
        channel.writeAndFlush(res);
    }
    
    public static void sendMsg(ChannelHandlerContext channel, ResultDto resultDto) {
        channel.writeAndFlush(resultDto);
    }

}
